package com.moon.back.util;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Pattern;

/**
 * 文件类型判断 工具类
 */
@Slf4j
public class TypeJudgeUtil {
   public static String[] types = new String[]{
           ".+(.txt|.doc|.docx|.xls|.xlsx|.html|.hml|.js|.pdf|.ppt|.cpp|.css)$"
           ,".+(.jpeg|.jpg|.png|.bmp|.gif|.svg|.webp)$"
           , ".+(.mp4|.avi|.wmv|.flv)$"
           ,".+(.mp3|.wav)$","^\\S+\\.*$"
           ,".+(.torrent)$"

   };

    /**
     *  文件判断类型工具类
     * @param name
     * @return type
     *   返回文件类型的标识
     */
 public static int typeJudge(String name){
     log.info("name:{}", name);
    for(int i =0; i< types.length; i++){
        Pattern pattern = Pattern.compile(types[i], Pattern.CASE_INSENSITIVE);
         if( pattern.matcher(name).find()){
             return i+1;
         }
    }
   return -1;
 }

}
